$(function () {
    $('#submit').tap(function () {
        var username = $('#username').val();
        var password = $('#password').val();
        var number = $('#number').val();

        var regu = /^[a-zA-Z_0-9]{4,32}$/;
        var regp = /^[a-zA-Z_0-9\!\@\#\$\%\^\&\*\.]{6,18}$/;
        var rege = /^[a-zA-Z0-9]+\@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/;

        if (!username) {
            alert('用户名不能为空！');
            change();
            return false;

        }
        if (!password) {
            alert('密码不能为空！');
            change();
            return false;

        }
        if (!number) {
            alert('验证码不能为空！');
            change();
            return false;
        }

        if (!regu.test(username)) {
            alert('用户名格式不正确！');
            change();
            return false;

        }
        if (!regp.test(password)) {
            alert('密码格式不正确！');
            change();
            return false;
        }
        var option = {
            type: 'post',
            url: HOST + '/admin/login.php',
            data: {
                user: username,
                psw: password,
                randomCode: number,
                postType: 'getCode'
            }
        };
        request(option).then(function (res) {
            alert(res.msg);
            if (res.status === 1) {
                LsyCookie.setItem('loginUserName', username, 60 * 24 * 7, '../');
                window.location.href = '../index.html';
            } else {
                $('#number').val('');
                change();
            }
        })
    });

    $('#code').tap(function () {
        change();
    });
    function change() {
        var r = Math.random();
        $('#code').attr('src', HOST + '/admin/code.php?w=128&h=40&fs=24&r=' + r);
    }
});